package kr.saeildamil.androidstudty.exam;

import java.util.ArrayList;

import kr.saeildamil.androidstudty.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;

public class ExamMyListAdapter extends BaseAdapter {
	Context mainContext;
	int icontextLayout;
	ArrayList<ExamMyItem> arSrc;
	LayoutInflater Inflater;
		
	
	public ExamMyListAdapter(Context mainContext, int icontextLayout, ArrayList<ExamMyItem> arSrc) {
		this.mainContext = mainContext;
		this.icontextLayout = icontextLayout;
		this.arSrc = arSrc;
		this.Inflater = (LayoutInflater) mainContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return arSrc.size();
	}

	@Override
	public String getItem(int position) {
		return arSrc.get(position).name;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final int pos = position;

		if (convertView==null){
			convertView = Inflater.inflate(icontextLayout, parent, false);
		}
		ImageView img = (ImageView) convertView.findViewById(R.id.exam_icontext_img);
		img.setImageResource(arSrc.get(position).iCon);
		
		TextView tv = (TextView) convertView.findViewById(R.id.exam_icontext_tv);
		tv.setText(arSrc.get(position).name);
		
		TextView detail = (TextView) convertView.findViewById(R.id.exam_icontext_detail);
		detail.setText(arSrc.get(position).detail);
		
		TextView btn = (TextView) convertView.findViewById(R.id.exam_icontext_btn);
		
		btn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				String str = getItem(pos) + "주문 합니다.";
				Toast.makeText(mainContext, str, Toast.LENGTH_LONG).show();
			}
		});
		return convertView;
	}	
}








